
***************************************************************************************
**************01: PREPARATION FOR ANALYSIS
***************************************************************************************

use "$datapath/online_survey_labeled", replace 

gen ___VARIABLES_FOR_ANALYSIS___=.

***************************************************************************************
**************SIA Measure generate


***recode true scams (1=1) (2=0), recode true non-scams (1=0) (2=1)
recode SIA_A_M1_Answer (1=0) (2=1), gen(SIA_Correct_M1) // no scam (received transfer)
recode SIA_A_M2_Answer (1=0) (2=1), gen(SIA_Correct_M2) // no scam (M-PESA app)
recode SIA_A_M3_Answer (1=1) (2=0), gen(SIA_Correct_M3) // scam (anniversary conversation starter) 
recode SIA_A_M4_Answer (1=1) (2=0), gen(SIA_Correct_M4) // scam (investment)
recode SIA_A_M5_Answer (1=1) (2=0), gen(SIA_Correct_M5) // scam (account suspended)
recode SIA_A_M6_Answer (1=1) (2=0), gen(SIA_Correct_M6) // scam (emergency contact)
recode SIA_B_M1_Answer (1=0) (2=1), gen(SIA_Correct_M7) // no scam (reversal request)
recode SIA_B_M2_Answer (1=0) (2=1), gen(SIA_Correct_M8) // no scam (duplicate account)
recode SIA_B_M3_Answer (1=1) (2=0), gen(SIA_Correct_M9) // scam (job)
recode SIA_B_M4_Answer (1=1) (2=0), gen(SIA_Correct_M10) // scam (winning)
recode SIA_B_M5_Answer (1=1) (2=0), gen(SIA_Correct_M11) // scam (Covid relief)
recode SIA_B_M6_Answer (1=1) (2=0), gen(SIA_Correct_M12) // scam (pay loan for contact)

forvalues i=1/12 {
       la var SIA_Correct_M`i' "Message identified correctly as scam/nonscam " 
  }
 
 	foreach x of varlist SIA_Correct_M1 SIA_Correct_M2 SIA_Correct_M3 SIA_Correct_M4 SIA_Correct_M5 SIA_Correct_M6 SIA_Correct_M7 SIA_Correct_M8 SIA_Correct_M9 SIA_Correct_M10 SIA_Correct_M11 SIA_Correct_M12 {
	label val `x' YesNo
}

gen SIA_M1_6=SIA_Correct_M1+SIA_Correct_M2+SIA_Correct_M3+SIA_Correct_M4+SIA_Correct_M5+SIA_Correct_M6  
gen SIA_M7_12=SIA_Correct_M7+SIA_Correct_M8+SIA_Correct_M9+SIA_Correct_M10+SIA_Correct_M11+SIA_Correct_M12
tab SIA_M1_6 OrderSIA_AB
tab SIA_M7_12 OrderSIA_AB

gen SIA_score_Part1=.
replace SIA_score_Part1=SIA_M1_6 if OrderSIA_AB==1
replace SIA_score_Part1=SIA_M7_12 if OrderSIA_AB==0 
la var SIA_score_Part1 "SIA: Total Score Block 1 (0-6)"
gen SIA_share_Part1 = SIA_score_Part1/6
la var SIA_share_Part1 "SIA  Block 1 (0-1)"

gen SIA_score_Part2=.
replace SIA_score_Part2=SIA_M1_6 if OrderSIA_AB==0
replace SIA_score_Part2=SIA_M7_12 if OrderSIA_AB==1 
la var SIA_score_Part2 "SIA: Total Score Block 2 (0-6)"
gen SIA_share_Part2 = SIA_score_Part2/6
la var SIA_share_Part2 "SIA  Block 2 (0-1)"

gen SIA_score_total=SIA_score_Part1+SIA_score_Part2
tab SIA_score_total
la var SIA_score_total "SIA: Total Score (0-12)"

drop SIA_M1_6 SIA_M7_12


* scam and official correct
local scams = "SIA_Correct_M3 SIA_Correct_M4 SIA_Correct_M5 SIA_Correct_M6 SIA_Correct_M9 SIA_Correct_M10 SIA_Correct_M11 SIA_Correct_M12"
local official = "SIA_Correct_M1 SIA_Correct_M2 SIA_Correct_M7 SIA_Correct_M8"

egen scam_correct_total = rowtotal(`scams')
egen official_correct_total = rowtotal(`official')
la var scam_correct_total "Correctly identified scams"
la var official_correct_total "Correctly identified non-scams"

*scam and official part 1 and part 2
gen official_correct_total_Part1      = SIA_Correct_M1+SIA_Correct_M2 if OrderSIA_AB==1
replace official_correct_total_Part1  = SIA_Correct_M7+SIA_Correct_M8 if OrderSIA_AB==0

gen scam_correct_total_Part1  = SIA_Correct_M3+SIA_Correct_M4+SIA_Correct_M5+SIA_Correct_M6 if OrderSIA_AB==1
replace scam_correct_total_Part1  = SIA_Correct_M9+SIA_Correct_M10+SIA_Correct_M11+SIA_Correct_M12 if OrderSIA_AB==0

gen official_correct_total_Part2  = SIA_Correct_M7+SIA_Correct_M8 if OrderSIA_AB==1
replace official_correct_total_Part2  = SIA_Correct_M1+SIA_Correct_M2 if OrderSIA_AB==0

gen scam_correct_total_Part2  = SIA_Correct_M9+SIA_Correct_M10+SIA_Correct_M11+SIA_Correct_M12 if OrderSIA_AB==1
replace scam_correct_total_Part2  = SIA_Correct_M3+SIA_Correct_M4+SIA_Correct_M5+SIA_Correct_M6 if OrderSIA_AB==0


forvalues i = 1/2{
gen scam_incorrect_total_Part`i'=4-scam_correct_total_Part`i'
gen official_incorrect_total_Part`i'=2-official_correct_total_Part`i'
}

*Share of correctly identified scam and official messages
gen scam_correct_share_Part1 = scam_correct_total_Part1/4
gen scam_correct_share_Part2 = scam_correct_total_Part2/4

gen official_correct_share_Part1 = official_correct_total_Part1/2
gen official_correct_share_Part2 = official_correct_total_Part2/2

* binary indicator for getting all messages of one type correct
gen all_scams_correct_Part1	= (scam_correct_total_Part1==4)
gen all_scams_correct_Part2	= (scam_correct_total_Part2==4)
gen all_official_correct_Part1 = (official_correct_total_Part1==2)
gen all_official_correct_Part2 = (official_correct_total_Part2==2)

label var scam_correct_share_Part1 "Scams correct share Block 1 (0-1)"
label var scam_correct_share_Part2 "Scams correct share Block 2 (0-1)"
label var official_correct_share_Part1 "Non-scams correct share Block 1 (0-1)"
label var official_correct_share_Part2 "Non-scams correct share Block 2 (0-1)"
label var all_scams_correct_Part1 "All scams correct Block 1 (0/1)"
label var all_scams_correct_Part2 "All scams correct Block 2 (0/1)"
label var all_official_correct_Part1 "All non-scams correct Block 1 (0/1)"
label var all_official_correct_Part2 "All non-scams correct Block 1 (0/1)"

***************************************************************************************
***SIA Measure Confidence

	  
	  egen SIA_confidence_mean = rowmean(SIA_*_M*_Confidence)
	  la var SIA_confidence_mean "Mean Confidence"
	  
	  rename SIA_A_M1_Confidence SIA_confidence_M1 
	  rename SIA_A_M2_Confidence SIA_confidence_M2 
	  rename SIA_A_M3_Confidence SIA_confidence_M3 
	  rename SIA_A_M4_Confidence SIA_confidence_M4 
	  rename SIA_A_M5_Confidence SIA_confidence_M5 
	  rename SIA_A_M6_Confidence SIA_confidence_M6 
	  rename SIA_B_M1_Confidence SIA_confidence_M7 
	  rename SIA_B_M2_Confidence SIA_confidence_M8 
	  rename SIA_B_M3_Confidence SIA_confidence_M9 
	  rename SIA_B_M4_Confidence SIA_confidence_M10 
	  rename SIA_B_M5_Confidence SIA_confidence_M11
	  rename SIA_B_M6_Confidence SIA_confidence_M12
	  
	  egen SIA_confidence1=rowmean(SIA_confidence_M1 SIA_confidence_M2 SIA_confidence_M3 SIA_confidence_M4 SIA_confidence_M5 SIA_confidence_M6)
	  egen SIA_confidence2=rowmean(SIA_confidence_M7 SIA_confidence_M8 SIA_confidence_M9 SIA_confidence_M10 SIA_confidence_M11 SIA_confidence_M12)

	  gen SIA_confidence_Part1=.
	  replace SIA_confidence_Part1=SIA_confidence1 if OrderSIA_AB==1
	  replace SIA_confidence_Part1=SIA_confidence2 if OrderSIA_AB==0 
	  la var SIA_confidence_Part1 "Mean Confidence in Block 1"
	  
	  gen SIA_confidence_Part2=.
	  replace SIA_confidence_Part2=SIA_confidence1 if OrderSIA_AB==0
	  replace SIA_confidence_Part2=SIA_confidence2 if OrderSIA_AB==1 
	  la var SIA_confidence_Part2 "Mean Confidence in Block 2"
	  
	  drop SIA_confidence1 SIA_confidence2

**Confidence in correctly and incorrectly identified questions 

forvalues i = 1(1)6{
    gen SIA_confidence_Part1_correct`i' = SIA_confidence_M`i' if SIA_Correct_M`i'==1 & OrderSIA_AB==1
	gen SIA_confidence_Part1_incorrect`i' = SIA_confidence_M`i' if SIA_Correct_M`i'==0 & OrderSIA_AB==1
		
	gen SIA_confidence_Part2_correct`i' = SIA_confidence_M`i' if SIA_Correct_M`i'==1 & OrderSIA_AB==0
	gen SIA_confidence_Part2_incorrect`i' = SIA_confidence_M`i' if SIA_Correct_M`i'==0 & OrderSIA_AB==0
}

forvalues i = 7(1)12{
    gen SIA_confidence_Part2_correct`i' = SIA_confidence_M`i' if SIA_Correct_M`i'==1 & OrderSIA_AB==1
	gen SIA_confidence_Part2_incorrect`i' = SIA_confidence_M`i' if SIA_Correct_M`i'==0 & OrderSIA_AB==1
	
	gen SIA_confidence_Part1_correct`i' = SIA_confidence_M`i' if SIA_Correct_M`i'==1 & OrderSIA_AB==0
	gen SIA_confidence_Part1_incorrect`i' = SIA_confidence_M`i' if SIA_Correct_M`i'==0 & OrderSIA_AB==0

}

*Average Confidence in Part 1 for correctly identified messages
egen SIA_confidence_Part1_correct= rowmean (SIA_confidence_Part1_correct*)
la var SIA_confidence_Part1_correct "Mean Confidence for correctly identified mess. Block 1"

*Average Confidence in Part 2 for correctly identified messages
egen SIA_confidence_Part2_correct= rowmean (SIA_confidence_Part2_correct*)
la var SIA_confidence_Part2_correct "Mean Confidence for correctly identified mess. Block 2"

*Average Confidence in Part 1 for incorrectly identified messages
egen SIA_confidence_Part1_incorrect= rowmean (SIA_confidence_Part1_incorrect*)
la var SIA_confidence_Part1_incorrect "Mean Confidence for incorrectly identified mess. Block 1"

*Average Confidence in Part 2 for incorrectly identified messages
egen SIA_confidence_Part2_incorrect= rowmean (SIA_confidence_Part2_incorrect*)
la var SIA_confidence_Part2_incorrect "Mean Confidence for incorrectly identified mess. Block 2"


*Confidence in scam and official messages 

gen confidence_official_part1 = (SIA_confidence_M1  + SIA_confidence_M2)/2 if OrderSIA_AB == 1
replace confidence_official_part1 =  (SIA_confidence_M7 + SIA_confidence_M8)/2 if OrderSIA_AB == 0

gen confidence_official_part2 = (SIA_confidence_M7 + SIA_confidence_M8)/2 if OrderSIA_AB == 1
replace confidence_official_part2 = (SIA_confidence_M1  + SIA_confidence_M2)/2  if OrderSIA_AB == 0

gen confidence_scam_part1 =  (SIA_confidence_M3+SIA_confidence_M4+SIA_confidence_M5+SIA_confidence_M6)/4 if OrderSIA_AB == 1
replace confidence_scam_part1 =  (SIA_confidence_M9 + SIA_confidence_M10 + SIA_confidence_M11 + SIA_confidence_M12)/4 if OrderSIA_AB == 0

gen confidence_scam_part2 = (SIA_confidence_M9 + SIA_confidence_M10 + SIA_confidence_M11 + SIA_confidence_M12)/4 if OrderSIA_AB == 1
replace confidence_scam_part2 = (SIA_confidence_M3+SIA_confidence_M4+SIA_confidence_M5+SIA_confidence_M6)/4 if OrderSIA_AB == 0

la var confidence_official_part1 "Mean Confidence non-scams Block 1"
la var confidence_official_part2 "Mean Confidence non-scams Block 2"
la var confidence_scam_part1 "Mean Confidence scams Block 1"
la var confidence_scam_part2 "Mean Confidence scams Block 2"

* Confidence in correct official and scam messages
egen 	confidence_offi_corr_part1 = rowmean(SIA_confidence_Part1_correct1 SIA_confidence_Part1_correct2) if OrderSIA_AB==1
ereplace confidence_offi_corr_part1 = rowmean(SIA_confidence_Part1_correct7 SIA_confidence_Part1_correct8) if OrderSIA_AB==0

egen 	confidence_offi_corr_part2 = rowmean(SIA_confidence_Part2_correct1 SIA_confidence_Part2_correct2) if OrderSIA_AB==0
ereplace confidence_offi_corr_part2 = rowmean (SIA_confidence_Part2_correct7 SIA_confidence_Part2_correct8) if OrderSIA_AB==1

egen 	confidence_offi_incorr_part1 = rowmean (SIA_confidence_Part1_incorrect1 SIA_confidence_Part1_incorrect2) if OrderSIA_AB==1
ereplace confidence_offi_incorr_part1 = rowmean (SIA_confidence_Part1_incorrect7 SIA_confidence_Part1_incorrect8) if OrderSIA_AB==0

egen 	confidence_offi_incorr_part2 = rowmean (SIA_confidence_Part2_incorrect1 SIA_confidence_Part2_incorrect2) if OrderSIA_AB==0
ereplace confidence_offi_incorr_part2 = rowmean (SIA_confidence_Part2_incorrect7 SIA_confidence_Part2_incorrect8) if OrderSIA_AB==1


egen 	confidence_scam_corr_part1 = rowmean (SIA_confidence_Part1_correct3 SIA_confidence_Part1_correct4 SIA_confidence_Part1_correct5 SIA_confidence_Part1_correct6) if OrderSIA_AB==1
ereplace confidence_scam_corr_part1 = rowmean (SIA_confidence_Part1_correct9 SIA_confidence_Part1_correct10 SIA_confidence_Part1_correct11 SIA_confidence_Part1_correct12) if OrderSIA_AB==0

egen 	confidence_scam_corr_part2 = rowmean (SIA_confidence_Part2_correct3 SIA_confidence_Part2_correct4 SIA_confidence_Part2_correct5 SIA_confidence_Part2_correct6) if OrderSIA_AB==0
ereplace confidence_scam_corr_part2 = rowmean (SIA_confidence_Part2_correct9 SIA_confidence_Part2_correct10 SIA_confidence_Part2_correct11 SIA_confidence_Part2_correct12) if OrderSIA_AB==1

egen 	confidence_scam_incorr_part1 = rowmean (SIA_confidence_Part1_incorrect3 SIA_confidence_Part1_incorrect4 SIA_confidence_Part1_incorrect5 SIA_confidence_Part1_incorrect6) if OrderSIA_AB==1
ereplace confidence_scam_incorr_part1 = rowmean (SIA_confidence_Part1_incorrect9 SIA_confidence_Part1_incorrect10 SIA_confidence_Part1_incorrect11 SIA_confidence_Part1_incorrect12) if OrderSIA_AB==0

egen 	confidence_scam_incorr_part2 = rowmean (SIA_confidence_Part2_incorrect3 SIA_confidence_Part2_incorrect4 SIA_confidence_Part2_incorrect5 SIA_confidence_Part2_incorrect6) if OrderSIA_AB==0
ereplace confidence_scam_incorr_part2 = rowmean (SIA_confidence_Part2_incorrect9 SIA_confidence_Part2_incorrect10 SIA_confidence_Part2_incorrect11 SIA_confidence_Part2_incorrect12) if OrderSIA_AB==1

drop SIA_confidence_Part1_correct1 SIA_confidence_Part1_incorrect1 SIA_confidence_Part2_correct1 SIA_confidence_Part2_incorrect1 SIA_confidence_Part1_correct2 SIA_confidence_Part1_incorrect2 SIA_confidence_Part2_correct2 SIA_confidence_Part2_incorrect2 SIA_confidence_Part1_correct3 SIA_confidence_Part1_incorrect3 SIA_confidence_Part2_correct3 SIA_confidence_Part2_incorrect3 SIA_confidence_Part1_correct4 SIA_confidence_Part1_incorrect4 SIA_confidence_Part2_correct4 SIA_confidence_Part2_incorrect4 SIA_confidence_Part1_correct5 SIA_confidence_Part1_incorrect5 SIA_confidence_Part2_correct5 SIA_confidence_Part2_incorrect5 SIA_confidence_Part1_correct6 SIA_confidence_Part1_incorrect6 SIA_confidence_Part2_correct6 SIA_confidence_Part2_incorrect6 SIA_confidence_Part2_correct7 SIA_confidence_Part2_incorrect7 SIA_confidence_Part1_correct7 SIA_confidence_Part1_incorrect7 SIA_confidence_Part2_correct8 SIA_confidence_Part2_incorrect8 SIA_confidence_Part1_correct8 SIA_confidence_Part1_incorrect8 SIA_confidence_Part2_correct9 SIA_confidence_Part2_incorrect9 SIA_confidence_Part1_correct9 SIA_confidence_Part1_incorrect9 SIA_confidence_Part2_correct10 SIA_confidence_Part2_incorrect10 SIA_confidence_Part1_correct10 SIA_confidence_Part1_incorrect10 SIA_confidence_Part2_correct11 SIA_confidence_Part2_incorrect11 SIA_confidence_Part1_correct11 SIA_confidence_Part1_incorrect11 SIA_confidence_Part2_correct12 SIA_confidence_Part2_incorrect12 SIA_confidence_Part1_correct12 SIA_confidence_Part1_incorrect12


* Weighted average of confidence for correctly and incorrecly identified messages
**************************************************************************************

* all messages
// number correct times confidence correct + number incorrect times inverted confidence incorrect
gen 	SIA_confidence_Part1_weighted = (SIA_score_Part1*SIA_confidence_Part1_correct) + ((6-SIA_score_Part1)*(SIA_confidence_Part1_incorrect*-1)) 
replace SIA_confidence_Part1_weighted = (SIA_score_Part1*SIA_confidence_Part1_correct) if SIA_confidence_Part1_incorrect == . // people who got everything right
replace SIA_confidence_Part1_weighted = ((6-SIA_score_Part1)*(SIA_confidence_Part1_incorrect*-1))  if SIA_confidence_Part1_correct == . // people who got everything wrong
replace SIA_confidence_Part1_weighted = SIA_confidence_Part1_weighted / 30  // scale from -1 to 1

gen 	SIA_confidence_Part2_weighted = (SIA_score_Part2*SIA_confidence_Part2_correct) + ((6-SIA_score_Part2)*(SIA_confidence_Part2_incorrect*-1)) 
replace SIA_confidence_Part2_weighted = (SIA_score_Part2*SIA_confidence_Part2_correct) if SIA_confidence_Part2_incorrect == . // people who got everything right
replace SIA_confidence_Part2_weighted = ((6-SIA_score_Part2)*(SIA_confidence_Part2_incorrect*-1))  if SIA_confidence_Part2_correct == . // people who got everything wrong
replace SIA_confidence_Part2_weighted = SIA_confidence_Part2_weighted / 30  // scale from -1 to 1

* scams
gen 	SIA_conf_Part1_scam_weighted = (scam_correct_total_Part1*confidence_scam_corr_part1) + (scam_incorrect_total_Part1*(confidence_scam_incorr_part1*-1))
replace SIA_conf_Part1_scam_weighted = (scam_correct_total_Part1*confidence_scam_corr_part1) if confidence_scam_incorr_part1 ==. // people who got everything right
replace SIA_conf_Part1_scam_weighted = (scam_incorrect_total_Part1*(confidence_scam_incorr_part1*-1)) if confidence_scam_corr_part1 == . // people who got everything wrong
replace SIA_conf_Part1_scam_weighted = SIA_conf_Part1_scam_weighted / 20

gen 	SIA_conf_Part2_scam_weighted = (scam_correct_total_Part2*confidence_scam_corr_part2) + (scam_incorrect_total_Part2*(confidence_scam_incorr_part2*-1))
replace SIA_conf_Part2_scam_weighted = (scam_correct_total_Part2*confidence_scam_corr_part2) if confidence_scam_incorr_part2 ==. // people who got everything right
replace SIA_conf_Part2_scam_weighted = (scam_incorrect_total_Part2*(confidence_scam_incorr_part2*-1)) if confidence_scam_corr_part2 == . // people who got everything wrong
replace SIA_conf_Part2_scam_weighted = SIA_conf_Part2_scam_weighted / 20

* non-scams
gen 	SIA_conf_Part1_offi_weighted = (official_correct_total_Part1*confidence_offi_corr_part1) + (official_incorrect_total_Part1*(confidence_offi_incorr_part1*-1))
replace SIA_conf_Part1_offi_weighted = (official_correct_total_Part1*confidence_offi_corr_part1) if confidence_offi_incorr_part1 ==. // people who got everything right
replace SIA_conf_Part1_offi_weighted = (official_incorrect_total_Part1*(confidence_offi_incorr_part1*-1)) if confidence_offi_corr_part1 == . // people who got everything wrong
replace SIA_conf_Part1_offi_weighted = SIA_conf_Part1_offi_weighted / 10

gen 	SIA_conf_Part2_offi_weighted = (official_correct_total_Part2*confidence_offi_corr_part2) + (official_incorrect_total_Part2*(confidence_offi_incorr_part2*-1))
replace SIA_conf_Part2_offi_weighted = (official_correct_total_Part2*confidence_offi_corr_part2) if confidence_offi_incorr_part2 ==. // people who got everything right
replace SIA_conf_Part2_offi_weighted = (official_incorrect_total_Part2*(confidence_offi_incorr_part2*-1)) if confidence_offi_corr_part2 == . // people who got everything wrong
replace SIA_conf_Part2_offi_weighted = SIA_conf_Part2_offi_weighted / 10

sum SIA_confidence_Part1_weighted SIA_conf_Part1_scam_weighted SIA_conf_Part1_offi_weighted SIA_confidence_Part2_weighted SIA_conf_Part2_scam_weighted SIA_conf_Part2_offi_weighted

la var SIA_confidence_Part1_weighted "Confidence weighted by SIA: Block 1"
la var SIA_confidence_Part2_weighted "Confidence weighted by SIA: Block 2"
la var SIA_conf_Part1_scam_weighted  "Confidence weighted by SIA: Scams in Block 1"
la var SIA_conf_Part2_scam_weighted "Confidence weighted by SIA: Scams in Block 2"
la var SIA_conf_Part1_offi_weighted "Confidence weighted by SIA: Non-scams in Block 1"
la var SIA_conf_Part2_offi_weighted "Confidence weighted by SIA: Non-scams in Block 2"



***************************************************************************************
*Time spent 

/*
First Click: Number of seconds from when the page loads to the first click
Last Click: Number of seconds from when the page loads to the click before the "Next" button is selected
Page Submit: Number of seconds from when the page loads to when the "Next" button is selected
Click Count: Number of a respondent clicks on a page
*/


forvalues i=1(1)6{
	
gen T_SIA_A_M`i'_duration=  T_SIA_A_M`i'_PageSubmit
gen T_SIA_B_M`i'_duration=  T_SIA_B_M`i'_PageSubmit
}

local timepartA = "T_SIA_A_M1_duration T_SIA_A_M2_duration T_SIA_A_M3_duration T_SIA_A_M4_duration T_SIA_A_M5_duration T_SIA_A_M6_duration"
local timepartB = "T_SIA_B_M1_duration T_SIA_B_M2_duration T_SIA_B_M3_duration T_SIA_B_M4_duration T_SIA_B_M5_duration T_SIA_B_M6_duration"

gen SIA_time_Part1= T_SIA_A_M1_duration + T_SIA_A_M2_duration + T_SIA_A_M3_duration + T_SIA_A_M4_duration + T_SIA_A_M5_duration + T_SIA_A_M6_duration if OrderSIA_AB==1
replace SIA_time_Part1= T_SIA_B_M1_duration + T_SIA_B_M2_duration + T_SIA_B_M3_duration + T_SIA_B_M4_duration + T_SIA_B_M5_duration + T_SIA_B_M6_duration if OrderSIA_AB==0

gen SIA_time_Part2= T_SIA_B_M1_duration + T_SIA_B_M2_duration + T_SIA_B_M3_duration + T_SIA_B_M4_duration + T_SIA_B_M5_duration + T_SIA_B_M6_duration if OrderSIA_AB==1
replace SIA_time_Part2= T_SIA_A_M1_duration + T_SIA_A_M2_duration + T_SIA_A_M3_duration + T_SIA_A_M4_duration + T_SIA_A_M5_duration + T_SIA_A_M6_duration if OrderSIA_AB==0

replace SIA_time_Part1=SIA_time_Part1/60
replace SIA_time_Part2=SIA_time_Part2/60

*Time Spent on Information Treatment_Feedback
gen Treatment_Tips_time= T_SIA_Treatment1_PageSubmit + T_SIA_Treatment2_PageSubmit + T_SIA_Treatment3_PageSubmit + T_SIA_Treatment5_PageSubmit + T_SIA_Treatment6_PageSubmit 
replace Treatment_Tips_time= 0 if Treatment_Tips_time==.

replace Treatment_Tips_time =  Treatment_Tips_time/60
sum Treatment_Tips_time

label var SIA_time_Part1 "Time spent on SIA Block 1"
label var SIA_time_Part2 "Time spent on SIA Block 1"
label var Treatment_Tips_time "Time spent on the Tips Treatment"

***************************************************************************************
*Drop HELP variables not needed for analysis 
drop SIA_score_Part1 SIA_score_Part2 SIA_score_total scam_correct_total official_correct_total official_correct_total_Part1 scam_correct_total_Part1 official_correct_total_Part2 scam_correct_total_Part2 scam_incorrect_total_Part1 official_incorrect_total_Part1 scam_incorrect_total_Part2 official_incorrect_total_Part2 confidence_offi_corr_part1 confidence_offi_corr_part2 confidence_offi_incorr_part1 confidence_offi_incorr_part2 confidence_scam_corr_part1 confidence_scam_corr_part2 confidence_scam_incorr_part1 confidence_scam_incorr_part2 T_SIA_A_M1_duration T_SIA_B_M1_duration T_SIA_A_M2_duration T_SIA_B_M2_duration T_SIA_A_M3_duration T_SIA_B_M3_duration T_SIA_A_M4_duration T_SIA_B_M4_duration T_SIA_A_M5_duration T_SIA_B_M5_duration T_SIA_A_M6_duration T_SIA_B_M6_duration

*************************
* save data prepared for analysis
save "$datapath/online_survey_analysis", replace 


**************************************************
*************************************************
***Generate data on respondent-vignette level 
*************************************************
**************************************************

preserve

**************Import data
use "$datapath/online_survey_analysis", clear

***Regressions SIA, effect of tips and incentives (data on respondent-vignette level)

gen id2=_n
reshape long SIA_Correct_M, i(id2) j(SIA_Message_number)
quietly tabulate SIA_Message_number, generate(D_SIA_M_)

merge m:1 SIA_Message_number using "$datapath/vignettes_tipsapply"

gen OrderSIA_Part2=.
forvalues i=1/6{
    replace OrderSIA_Part2=0 if D_SIA_M_`i'==1 & OrderSIA_AB==1 
  }
  forvalues i=1/6{
    replace OrderSIA_Part2=1 if D_SIA_M_`i'==1 & OrderSIA_AB==0
  }
  forvalues i=7/12{
    replace OrderSIA_Part2=1 if D_SIA_M_`i'==1 & OrderSIA_AB==1 
  }
    forvalues i=7/12{
    replace OrderSIA_Part2=0 if D_SIA_M_`i'==1 & OrderSIA_AB==0
  }
  
tab OrderSIA_Part2 if OrderSIA_AB==1 & D_SIA_M_1==1
tab OrderSIA_Part2 if OrderSIA_AB==1 & D_SIA_M_7==1
tab OrderSIA_Part2 if OrderSIA_AB==0 & D_SIA_M_1==1
tab OrderSIA_Part2 if OrderSIA_AB==0 & D_SIA_M_7==1
la var OrderSIA_Part2 "Message shown in Part 2"

global FE_SIA_message D_SIA_M_2 D_SIA_M_3 D_SIA_M_4 D_SIA_M_5 D_SIA_M_6 D_SIA_M_7 D_SIA_M_8 D_SIA_M_9 D_SIA_M_10 D_SIA_M_11 D_SIA_M_12

gen Part2_Tips_noinc=(OrderSIA_Part2==1 & Treatment_Tips ==1 & Treatment_Incentives ==0)
gen Part2_Tips_inc=(OrderSIA_Part2==1 & Treatment_Tips ==1 & Treatment_Incentives ==1)

gen non_scam = (SIA_Message_number ==1 | SIA_Message_number==2 | SIA_Message_number==7 | SIA_Message_number==8)
gen scam = (non_scam==0)

**** difficulty: average correct answers in part 1
bysort SIA_Message_number: egen difficulty_int =mean(SIA_Correct_M) if OrderSIA_Part2==0
bysort SIA_Message_number: egen difficulty = max(difficulty_int)

egen median_difficulty = median(difficulty)
gen hard_task = (difficulty < median_difficulty)

label define hard_task 0 "easy" 1 "difficult"
label values hard_task hard_task 

label define Tips_apply 0 "No Marker" 1 "Scam Marker"
label values Tips_apply Tips_apply

* save respondent-vignette level data
save "$datapath/online_survey_analysis_respondent_vignette_level", replace 

restore


***************************************************************************************

